﻿/// <reference path="_namespace.js" />
/// <reference path="../components/Container.js" />

/*****************************************************************************
Ajax library class definition. Kevin Robinson 2006.
Class: ajax.windows.Window
/*****************************************************************************/


ajax.lang.addNamespace("ajax.windows");

//-----------------------------------------------------------------------------
ajax.windows.Window = function(doc, sLayerName, w, h, parentNode) // Constructor
{    
    ajax.windows.Window.superConstructor.call(this, doc, parentNode, sLayerName, w, h);
    
	// Properties
	this.content            = null;			
    this.tag				= null;
    
    // Styles
	this.itemStyle = 
	{
	    position       : "absolute",
	    backgroundColor: "#EEEEEE",
	    left           : "0px",
	    top            : "0px",
	    fontFamily     : "Arial",
	    fontSize       : "12px",
        fontWeight     : "normal",
        zIndex         : 101,
        borderTop      : "thin solid #EEEEEE",
        borderRight    : "thin solid #666666",
        borderBottom   : "thin solid #666666",
        borderLeft     : "thin solid #EEEEEE",        
        overflow       : "hidden",
        padding        : "2px",
        cursor         : "default"
	};		
}

//-----------------------------------------------------------------------------
ajax.lang.extend("ajax.windows.Window", "ajax.components.Container"); // Inherit



ajax.windows.Window.prototype.load = function()
{
	// Create this now, in its hidden state
	this.create();
    
	this.addHandlers();
	this.setSize(this.width, this.height);	
	
	// Fire onLoad event
	this.onLoad.call(this);
}

ajax.windows.Window.prototype.addHandlers = function()
{
    // We do not want the user to "select" from the text on a winform
    ajax.lang.getEvent(this.window, this.layer, "onselectstart").addListener(this.noSelectHandler);
}

//-----------------------------------------------------------------------------
ajax.windows.Window.prototype.create = function()
{
    var prevDiv = this.doc.getElementById(this.layerName);
    if (prevDiv)
    {
        ajax.debug.Output.writeLn("Window " + this.layerName + " already exists so destroying it to create new.");
        ajax.lang.safeDestroy(prevDiv);
    }    
        
    var self                        = this;
	this.layer 						= this.doc.createElement("div");
	this.layer.setAttribute("name", this.layerName);
	this.layer.id 					= this.layerName;   
   
   
    // Copy in the item style for this window.
    this.copyProperties(this.layer.style, this.itemStyle); 
    // Set the dimensions       
	this.layer.style.width          = this.width + "px";
	this.layer.style.height         = this.height + "px";
	
	// Pop in an inner Div, well call "content"
	this.content                    = this.doc.createElement("div");	
	// The content is always at the correct size
	this.content.style.width        = this.width + "px";
	this.content.style.height       = this.height + "px";
	
	// Append the content to the layer
	this.layer.appendChild(this.content);
	// Append the layer to the document
	this.parentNode.appendChild(this.layer);
	
	return true;
};


//-----------------------------------------------------------------------------
ajax.windows.Window.prototype.toString = function()
{
    return "ajax.windows.Window";
}

//-----------------------------------------------------------------------------
ajax.windows.Window.prototype.toClassName = function()
{
    return ajax.lang.getClassName("ajax.windows.Window");
}

//-----------------------------------------------------------------------------
ajax.windows.Window.cast = function(obj)
{///<returns type="ajax.windows.Window"/>
    return obj;
}